package main

import "fmt"

type MyError struct {
	msg  string
	code int
}

func (e MyError) Error() string {
	return fmt.Sprint("错误信息：", e.msg, "状态码：", e.code)
}

func test2(i int) (int, error) {
	if i != 0 {
		return i, &MyError{
			msg:  "i 不为0",
			code: 200,
		}
	}
	return i, nil
}

func main() {
	i, err := test2(1)
	if err != nil {
		fmt.Println(err)
		myerr, ok := err.(*MyError)
		if ok {
			fmt.Println(myerr.msg)
			fmt.Println(myerr.code)
		}
	}
	fmt.Println(i)
}
